package project2.ui.game.auto;

import project2.entity.enemy.EnemyPlane;
import project2.resources.Sounds;
import project2.type.EnemyPlaneType;
import project2.ui.game.GamePlayingPanel;

public class EnemyPlaneMove {

    private final GamePlayingPanel panel;

    public EnemyPlaneMove(GamePlayingPanel panel) {
        this.panel = panel;
    }

    public void run(EnemyPlane p) {
        if (p == null || p.isKilled()) {
            return;
        }

        p.setPosY(p.getPosY() + p.getSpeed());// 更改位置
        if (p.getPosY() >= panel.getHeight()) {// 超出面板范围，则清除
            if (p.getEnemyType().equals(EnemyPlaneType.BOSS_ENEMY_PLANE)) {
                Sounds.bossPlaneFlyingSoundPlayer.stop();
            }
            panel.enemyPlanes.remove(p);
        } else if (p.getRectangle().intersects(panel.myPlane.getRectangle())) {// 敌机与主角碰撞检测
            if (panel.myPlane.isAlive()) {
                panel.stopGame();
            }
        }

    }
}
